import json
from collections import namedtuple

# creates the Argument 'class'
# names can be any public value
# input type can only be 'text' for now
Argument = namedtuple('Argument', 'name input_type')

def _to_text_field(argument):
    base_form = "    %s: <input type='text' name=\"%s\"/>\n"
    return base_form % (argument.name, argument.name)

def _to_checkbox_field(argument):
    base_form = "    <input type='checkbox' name=\"%s\"> %s </input>\n"
    return base_form % (argument.name, argument.name)

def tool_to_HTML(task_name):
    base_element = "<a href='google.com' onclick=\"return selectTask('%s');\"> %s </a>\n"
    return base_element % (task_name, task_name)

def arguments_to_HTML(task_name, arguments):
    field_names = []
    form  = "<form class='inputForm' id='inputForm' onsubmit='return false;'>\n"
    form += "   <input type='hidden' name='taskName' value='%s'/>\n"
    form %= task_name
    for argument in arguments:
        if argument.input_type == 'text':
            form += _to_text_field(argument)
        if argument.input_type == 'checkbox':
            form += _to_checkbox_field(argument)
        field_names.append(argument.name)
    form += "   <input type='button' name='submit' value='submit' onclick=\"return runTask('%s');\"/>\n" % task_name
    form += "</form>\n"
    return form
            
